<template>
	<view class="bg-white">
		<view class="text-xxl padding text-black text-bold">
			企业授权
		</view>
		<view class="padding-sm" style="background-color: #ebfbef;color: #569a62;font-size: 24rx;">
			请完善您的企业真实信息，进行企业授权
		</view>
		<view class="padding-sm">
			<u-form :model="form" ref="uForm">
				<u-form-item label="企业名称" prop="name" :label-position="labelPosition" :label-style="labelStyle"
					style="color: #000000;font-weight: bold;font-size: 4rpx;line-height: 26rpx;">
					<u-input :border="border" v-model="form.name" placeholder="请输入企业名称" />
				</u-form-item>
				<u-form-item label="企业证件号" prop="registerNo" :label-position="labelPosition"
					style="color: #000000;font-weight: bold;font-size: 48rpx;">
					<u-input :border="border" v-model="form.registerNo" placeholder="统一社会信用代码/工商注册号" />
				</u-form-item>
				<u-form-item label="法人姓名" prop="legalPerson" :label-position="labelPosition"
					style="color: #000000;font-weight: bold;font-size: 48rpx;">
					<u-input :border="border" type="tel" v-model="form.legalPerson" placeholder="请输入法人真实姓名" />
				</u-form-item>
				<u-form-item label="法人身份证号" prop="legalPersonId" :label-position="labelPosition"
					style="color: #000000;font-weight: bold;font-size: 48rpx;">
					<u-input :border="border" v-model="form.legalPersonId" placeholder="请输入法人身份证号" />
				</u-form-item>
			</u-form>
			<view class="">
				<button class="cu-btn block bg-blue margin-tb-sm lg" type="" @click="update">进入企业实名认证</button>
			</view>
		</view>
	</view>
</template>

<script>
	var that
	export default {
		data() {
			return {
				form: {
					name: '',
					registerNo: '',
					legalPerson: '',
					legalPersonId: ''
				},
				agreement:false,
				labelPosition: 'top',
				border: false,
				labelStyle: {
					'line-height': '26rpx'
				},
				rules: {
					name: [{	
						required: true, 
						message: '请输入企业名称',
						trigger: ['change', 'blur'],
					}],
					registerNo: [{
						required: true, 
						message: '请输入统一社会信用代码/工商注册号',
						trigger: ['change', 'blur'],
					}],
					legalPerson: [{
						required: true, 
						message: '请输入法人真实姓名',
						trigger: ['change', 'blur'],
					}],
					legalPersonId: [{
						required: true, 
						message: '请输入法人身份证号',
						trigger: ['change', 'blur'],
					}],					
				}				
			}
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		onLoad(e) {
			that = this
			if (e.id) {
				that.$u.post('index/company', {op:'find',id:e.id}).then(res => {
					that.form = res
				})
			}
		},
		methods: {
			companyChange(e){
				that.form.company = e
			},
			xiankankan(){
				uni.switchTab({
					url:'/pages/index/index',
					success() {
						uni.setStorageSync('islogin', 1);
					}
				})				
			},
			update() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						that.form.op = 'add'
						that.$u.post('index/company', that.form).then(res => {
							that.$u.post('qiyue/h5page', {
								name: res.name,
								registerNo: res.registerNo,
							}).then(res => {
								if (res.code !== 0) {
									uni.showToast({
										title: res.message,
										duration: 2000,
										icon: "none"
									});
									return false
								}
								uni.navigateTo({
									url: '/pages/center/index?url=' + encodeURIComponent(JSON.stringify(res.authurl))
								})
							})
						})
					} else {
						console.log('验证失败');
					}
				});
				
			}
		}
	}
</script>

<style scoped lang="scss">
	.agreement {
		display: flex;
		align-items: center;
		margin: 40rpx 0;

		.agreement-text {
			padding-left: 8rpx;
			color: $u-tips-color;
		}
	}
</style>
